<template>
	<view class="qrcode">
		<view class="top d-flex">
			<u-image :src="data.goods_info.goods_image" width="160rpx" height="160rpx" radius="12rpx"></u-image>
			<view style="margin-left: 30rpx;">
				<view class="name ">{{ data.goods_name}}</view>
				<!-- <view class="date" v-for="(item,index) in data.consumption_type" :key="index">{{ item}}</view> -->
				<!-- <view>
					<view class="date">{{ data.goods_name}}</view>
				</view> -->
				<view class="venue_name">{{data.points}}积分</view>
				<view class="venue_name">领取截至{{data.end_time}}</view>
				<!-- <view class="venue_name" v-if="options.title == '我的场地'">{{ data.start_time }} - {{ data.end_time }}</view>
				<view class="venue_name" v-else>{{ data.yxq}}</view>
				<view class="venue_name"  v-if="options.title == '我的场地'">{{data.court_name}}</view>
				<view class="venue_name" v-else>{{data.venue_name}}</view> -->
				<!-- <view class="share_a" v-if="data.field_type == 2"> 名额场 </view>
				<view class="share_a" style="color: coral;" v-if="data.field_type == 1"> 包场 </view>
				<view class="share_a" v-if="data.field_type == 3"> 拼团 </view> -->
			</view>
		</view>

		<view class="qrcode-wrapper">
			<view class="d-flex align-center flex-column" :hidden="!vueShowModel">
				<view class="destroy-code">兑换码：{{ code }}</view>
				<!-- <view class="tip">请在核验时出示，注意保管勿泄露</view> -->
				<!-- <u-image width="370rpx" height="370rpx"></u-image> -->
				<uQRCode ref="qrcode" canvas-id="qrcode" :value="code" size="185"></uQRCode>
				<view class="tip">请向商家出示二维码，扫描后即可兑换</view>
				<view class="tips" @click="addresslist" style="width:auto">
					<view style="line-height: 30rpx;margin:0 auto;text-align: center;width: auto;display: block;">
						<image style="width: 26rpx;height: 26rpx;float:left;"
							src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/20f18eef6cab3f1f68e9b68c73b541cda0b972a7.png"
							mode=""></image>
						<text style="line-height: 26rpx;height: 26rpx;display: block;float:left;width: 85%;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
				text-align: center;">兑换地点:{{data.addr_info.address}}</text>
						<image style="width: 26rpx;height: 26rpx;float:left;"
							src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/446fbdc971425fe00a703074be1e06c384f9526e.png"
							mode=""></image>
					</view>
					<!-- <view class="" v-if="options.beShare == 0"> -->

					<!-- 开场前<text style="color: #ffaa00;">{{ data.permit_in_time }}</text> 分钟允许进场；结束后<text
							style="color: #ffaa00;">{{ data.permit_in_time }}</text> 分钟离场，请勿超时！</view> -->
				</view>
			</view>
		</view>
		<!-- <camera device-position="back" flash="off" @error="error" style="width: 100%; height: 300px;"></camera>
		<button type="primary" @click="takePhoto">拍照</button>
		<view>预览</view>
		<image mode="widthFix" :src="src"></image>
		<button type="primary" @click="scanCode">扫码</button> -->

	</view>
</template>

<script>
	import uQRCode from '@/uni_modules/Sansnn-uQRCode/components/u-qrcode/u-qrcode.vue'
	const person = require("@/api/personal/index.js");
	export default {
		components: {
			uQRCode
		},
		data() {
			return {
				data: {},
				options: {},
				code: '',
				not_in_time: '',
				vueShowModel: true, //默认不显示
				chosen_id: '',
				src: ""
			}
		},
		onLoad(options) {
			this.options = options;

			uni.setNavigationBarTitle({
				title: '我的兑换'
			});
			let that = this;
			this.orderDetail();

		},
		onShow() {
			let that = this;
			this.orderDetail();
		},

		methods: {
			// 获取我的卡包详情
			async orderDetail() {
				let params = {
					project_id: getApp().globalData.projectId,
					app_id: this.$https.weixinAppId,
					id: this.options.id
				}
				let res = await person.orderDetail(params)
				if (res.code === 1) {
					this.data = res.data.result
					this.code = res.data.result.code
					// this.getDynamicCode()
				}
			},
			addresslist() {
				uni.openLocation({
					latitude: Number(this.data.addr_info.lat), //要去的纬度-地址
					longitude: Number(this.data.addr_info.lng), //要去的经度-地址
					address: this.data.addr_info.address, //要去的具体地址
					//此处踩坑的问题2：
					//latitude 和 longitude的值一定要是number类型。
					//所以传递的时候需要使用Number将其转换一下。
				})
			},
			scanCode() {
				// 允许从相机和相册扫码
				uni.scanCode({
					scanType: ["qrCode"],
					success: (res) => {
						if (res.result) {
							const val = res.result;
						} else {
							console.log('请重新扫描');
							return false;
						}
					},
					fail: (res) => {
						console.log('未识别到二维码');
					}
				})
			},
			// 对扫码后，得到的url地址参数的处理。
			parseUrl(url) {
				let pattern = /(\w+)=([0-9a-zA-Z\u4e00-\u9fa5]+)/ig;
				let parames = {};
				url.replace(pattern, function(a, b, c) {
					parames[b] = c;
				});
				return parames; // 返回一个参数名：参数值 的对象。
			},
			takePhoto() {
				const ctx = uni.createCameraContext();
				ctx.takePhoto({
					quality: 'high',
					success: (res) => {
						this.src = res.tempImagePath
					}
				});
			},
			error(e) {
			}
		}
	}
</script>

<style lang="scss" scoped>
	// @import url("@/static/css/personal/index.css");
	.qrcode {
		min-height: 100vh;
		background-color: #F8654E;
		padding: 20rpx;
		padding-bottom: calc(20rpx + env(safe-area-inset-bottom));

		.top {
			border-radius: 20rpx;
			padding: 30rpx 24rpx;
			background-color: #fff;
			margin-bottom: 30rpx;

			.share_a {
				width: 140rpx;
				height: 60rpx;
				border-radius: 50%;
				position: absolute;
				top: 3.3%;
				right: 3rpx;
				font-size: 28rpx;
				color: #999999;
			}

			.name {
				font-weight: bold;
				color: #333;
				margin-bottom: 20rpx;
			}

			.date {
				background-color: #f3f3f3;
				color: rgb(136, 136, 136);
				font-size: 24rpx;
				border-radius: 100px;
				padding: 4rpx 20rpx;
				float: left;
				margin-right: 10rpx;
			}

			.venue_name {
				font-size: 30rpx;
				color: #000;
				margin-top: 20rpx;
			}
		}

		.qrcode-wrapper {
			border-radius: 10rpx;
			background-color: #fff;
			overflow: hidden;
			padding-bottom: 60rpx;

			.choose {
				background-color: #f7f7f7;
				padding: 49rpx 30rpx 51rpx 31rpx;
			}

			.chooses {
				background-color: #f7f7f7;
				padding: 75rpx 30rpx 80rpx 31rpx;

				.my-menu {
					position: absolute;
					// top: 240rpx;
					// left: 5%;
					transform: translate(-50%);
				}

				.cates {
					display: flex;
					justify-content: center;
					position: absolute;
					top: 50%;
					left: 22rpx;
					transform: translateY(-50%);
				}

				.catess {
					display: flex;
					justify-content: center;
					position: absolute;
					top: 50%;
					left: 210rpx;
					transform: translateY(-50%);
				}

				.catesss {
					display: flex;
					justify-content: center;
					position: absolute;
					top: 50%;
					left: 390rpx;
					transform: translateY(-50%);
				}

				.cate-item {
					width: 200rpx;
					font-size: 24rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
				}

				.cate-item text {
					margin-top: 10rpx;
				}

			}

			.destroy-code {
				color: #2f75fa;
				// margin: 40rpx 0;
				margin: 40rpx 0 20rpx 0;
			}

			.tip {
				margin: 25rpx 0 30rpx 0;
				color: #999;
				font-size: 28rpx;
			}

			.tips {
				// margin-top: 20rpx;
				color: #000000;
				font-size: 28rpx;
				width: 100%;
				height: 60rpx;
				// width: 85%;
				// white-space: nowrap;
				// overflow: hidden;
				// text-overflow: ellipsis;
				// text-align: center;
				// margin: 0 auto;
			}
		}

		.fenxiang {
			color: #fff;
			margin-top: 29rpx;
		}

		.vueBgdCol {
			position: fixed;
			top: 0%;
			left: 0%;
			width: 100%;
			height: 100%;
			background-color: black;
			z-index: 1001;
			-moz-opacity: 0.8;
			opacity: 0.8;
			filter: alpha(opacity=88);
		}

		.vueContant {
			position: fixed;
			top: 40%;
			left: 50%;
			width: 600rpx;
			height: 300rpx;
			margin-left: -305rpx;
			margin-top: -76px;
			background-color: white;
			z-index: 1002;
			overflow: auto;
			border-radius: 20rpx;
		}

		.vueTitle {
			display: flex;
			justify-content: center;
			font-size: 28rpx;
			padding-top: 55rpx;
			font-weight: 600;
		}

		.vueContants {
			position: fixed;
			top: 40%;
			left: 50%;
			width: 600rpx;
			height: 330rpx;
			margin-left: -320rpx;
			margin-top: -76px;
			background-color: white;
			z-index: 1002;
			overflow: auto;
			border-radius: 20rpx;
		}

		.vueTits {
			display: flex;
			justify-content: center;
			font-size: 28rpx;
			padding-top: 75rpx;
			font-weight: 600;
		}

		.vueDetail {
			font-size: 28rpx;
			color: #646566;
			display: flex;
			// justify-content: center;
			padding: 32rpx;
			height: 48rpx;
			margin-right: 20rpx;
		}

		/deep/.u-tag {
			margin-left: 20rpx;

		}

		/deep/.u-textarea {
			background-color: #f3f3f3;
			margin-top: 80rpx;
		}

		/deep/.u-button {
			width: 30%;
			height: 60rpx;
		}

		.vueBtn {
			display: flex;
			margin-top: 80rpx;
		}

		.vueBtns {
			display: flex;
			margin-top: 100rpx;
		}

		.vueBtn span {
			width: 320rpx;
			height: 96rpx;
			font-size: 24rpx;
			font-weight: 600;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.vueBtn span:first-child {
			border-top: 1px solid #ebedf0;
		}

		.vueBtn span:last-child {
			color: #ee0a24;
			border-top: 1px solid #ebedf0;
			border-left: 1px solid #ebedf0;
		}
	}
</style>
